<?php
namespace app\index\controller;
use think\Controller;
use think\Request;
use think\Db;


//公共控制器
class IndexController extends Controller
{

	public function _initialize()
    {	
    	if(empty(input('session.user.id'))){
			//跳转到 登陆页
			$this->redirect("index/user/login");
		}

        //用户
		$userList = db('user')->where('id',input('session.user.id'))->find();
        $this->assign('userList', $userList);

        //好友
        $friendList = Db::query('select u.icon,u.nickname,u.sex,u.id,u.sightml,u.province from bbs_user u where u.id in (select t1.fid from (select * from bbs_friend where use_id = '.input('session.user.id').') as t1 inner join (select * from bbs_friend where fid = '.input('session.user.id').') as t2 on t1.fid = t2.use_id)');
        $this->assign('friendList', $friendList);

        //统计数量
        $rizhi_num = count(db('rizhi')->where('use_id',input('session.user.id'))->select());
        $this->assign('rizhi_num',$rizhi_num);
        $img_num = count(db('img')->where('use_id',input('session.user.id'))->select());
        $this->assign('img_num',$img_num);  
        $guanzhu_num = count(db('friend')->where('use_id',input('session.user.id'))->select());
        $this->assign('guanzhu_num',$guanzhu_num); 
        $fensi_num = count(db('friend')->where('fid',input('session.user.id'))->select()); 
        $this->assign('fensi_num',$fensi_num);
 
        $friend_num = count(Db::query('select t1.* from (select * from bbs_friend where use_id = '.input('session.user.id').') as t1 inner join (select * from bbs_friend where fid = '.input('session.user.id').') as t2 on t1.fid = t2.use_id'));
        $this->assign('friend_num',$friend_num);
        

    }



    public function _empty($name)
    {

        // return abort(404,'页面不存在');
        return view('404/404');
        
    }



}